﻿using System.Reflection;
using System.Resources;

namespace Dsl.Ped.Common.Helpers
{
    /// <summary>
    /// Helper of the <see cref="string"/>
    /// </summary>
    public class StringHelper
    {
        /// <summary>
        /// Localize <see cref="string"/> against the Lang dictionary of specific resource and <see cref="Assembly"/>
        /// </summary>
        /// <param name="str">String to localize</param>
        /// <param name="resourceAssembly"><see cref="Assembly"/> where the resource is defined</param>
        /// <param name="resourceManagerBaseName">Base name of the resource</param>
        /// <returns>Localized dictionary item if exists, items.ToString() itself otherwise</returns>
        public static string Localize(string str, Assembly resourceAssembly, string resourceManagerBaseName)
        {
            var rm = new ResourceManager(resourceManagerBaseName, resourceAssembly);
            return rm.GetString(str) ?? str;
        }
    }
}
